package javaer.starter.placeholder;

import java.util.Objects;

public class ParameterMapping implements Comparable {

    private String content;

    public ParameterMapping(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return content;
    }

    @Override
    public int hashCode() {
        return content.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ParameterMapping p = (ParameterMapping) o;
        return Objects.equals(content, p.getContent());
    }

    @Override
    public int compareTo(Object o) {
        ParameterMapping o1 = (ParameterMapping) o;
        String target = o1.getContent();
        String source = this.content;
        char[] chars1 = target.toCharArray();
        char[] chars2 = source.toCharArray();
        int i = 0;
        while (i < chars1.length && i < chars2.length) {
            if (chars1[i] > chars2[i]) {
                return 1;
            } else if (chars1[i] < chars2[i]) {
                return -1;
            } else {
                i++;
            }
        }
        if (i == chars1.length) {  //o1到头
            return -1;
        }
        if (i == chars2.length) { //o2到头
            return 1;
        }
        return 0;
    }
}
